<?php
$adtitle = $_POST['adtitle'];
$addesc  = $_POST['addesc'];
$adcode  = $_POST['adcode'];
$adtype  = $_POST['adtype'];
$ademail = $_POST['ademail'];
$adloc   = $_POST['adloc'];
$adsal   = $_POST['adsal'];

if(isset($adtitle)){ // Εάν έχει τιμή ο τίτλος αγγελίας
 		// Εισαγωγή νέα αγγελίας, default approved
        $query = "INSERT INTO ADS (ad_title, ad_desc, ad_code, ad_type, ad_email, ad_salary, user_autocomplete, ad_isAproved)
        VALUES ('".$adtitle."', '".$addesc."', '".$adcode."', '".$adtype."', '".$ademail."', '".$adsal."', '".$adloc."', 1)";

        $set->qry($query);

        include 'adv_search.php';
        include 'adv_results.php';
}
else
{
?>
<div id = "user_details">

    <div>
        <form action=<?php echo "advertisements.php?action=new"?> method="post">

        <table class="table_search">
            <tr>
                <td>Title</td>
                <td><input id="adtitle" class="search_input" type="text" name="adtitle"></td>
            </tr>
            <tr>
                <td>Description</td>
                <td><input id="addesc" class="search_input" type="text" name="addesc"></td>
            </tr>
            <tr>
                <td>Code</td>
                <td><input id="addesc" class="search_input" type="text" name="addesc"></td>
            </tr>
            <tr>
                <td>Type</td>
                <td><input id="adtype" class="search_input" type="text" name="adtype"></td>
            </tr>
            <tr>
                <td>Salary</td>
                <td><input id="adsal" class="search_input" type="text" name="adsal"></td>
            </tr>
            <tr>
                <td>Email</td>
                <td><input id="ademail" class="search_input" type="text" name="ademail"></td>
            </tr>
            <tr>
                <td>Location</td>
                <td><input id="adloc" class="search_input" type="text" name="adloc"></td>
            </tr>                        
        </table>
        <table class="table_search">
            <tr>
                <td>
                    <input type="submit"  value="Save" id="save_btn">
                </td>
            </tr>
        </table>
    </div>
    </form>
</div>
<?php
}
?>